﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace ParkingLot.Utility
{
    public class ConfigHelp
    {
        /// <summary>
        /// 设置值
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool SetValue(string key, string value)
        {
            try
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection sec = (AppSettingsSection)config.AppSettings;
                if (!sec.Settings.AllKeys.Contains(key))
                {
                    return false;
                }
                sec.Settings[key].Value = value;
                config.Save();
                ConfigurationManager.RefreshSection("appSettings");
                return true;
            }
            catch (Exception exception)
            {
                return false;
            }
        }
    }
}
